<template>
    <IContent :spinShow="loading">
        <alert banner type="warning" style="margin-bottom: 0;">
            同一个料号对应多个序号时，系统只会取最小的那个序号。
        </alert>
        <ISearch v-model="search">
            <FormItem label="海关料号">
                <Input v-model="search.unique" size="small"></Input>
            </FormItem>
            <FormItem label="账册序号">
                <Input v-model="search.record_no" size="small"></Input>
            </FormItem>
            <FormItem :label-width="1">
                <Button type="primary" icon="ios-search" @click="getLists(1)" size="small">搜索</Button>
                <Button type="info" icon="ios-add"size="small" @click="openComponent('IExport')">导入</Button>
            </FormItem>
        </ISearch>
        <ITable :current="page.current" :table="table" :total="page.total" @on-page-change="pageChange">
            <template slot-scope="{ row, index }" slot="action">
                <PoptipButton size="small" content="确认要删除产品账册吗?"
                              @on-ok="submitForDestroy(row.id)">删除
                </PoptipButton>
            </template>
        </ITable>

        <component v-if="componentProps.value" :is="componentProps.view" v-model="componentProps.value" :props="componentProps.props"
                   @input="getLists(page.current)"></component>
    </IContent>
</template>

<script>
    import contentListPage from "../../../mixins/contentListPage";
    import IContent from "../../../components/content/index";
    import ISearch from "../../../components/content/search";
    import ITable from "../../../components/content/table";
    import contentDrawer from "../../../mixins/contentDrawer";
    import RemoteSelect from "../../../components/form/remoteSelect";
    import IExport from './export'
    import PoptipButton from "../../../components/content/poptipButton";

    export default {
        name: "index",
        components: {PoptipButton, RemoteSelect, ITable, ISearch, IContent, IExport},
        mixins: [contentListPage, contentDrawer],
        data(){
            return {
                table: {
                    columns: [
                        {
                            title: '海关料号',
                            key: 'unique'
                        },
                        {
                            title: '账册序号',
                            key: 'record_no'
                        },
                        {
                            title: '操作',
                            slot: 'action'
                        }
                    ]
                },
                search: {}
            }
        },
        methods: {
            getLists(page) {
                this.loading = true;
                this.$http.get(`product/book`, {
                    params: Object.assign({}, this.search, {page: page})
                }).then((data) => {
                    this.table.data = data.data
                    this.page.total = data.total
                    this.page.current = data.current_page
                }).finally(() => {
                    this.loading = false;
                });
            },
            submitForDestroy(id){
                this.loading = true;
                this.$http.delete(`product/book/${id}`).then(() => {
                    this.getLists(this.page.current)
                }).finally(() => {
                    this.loading = false;
                });
            }
        }
    }
</script>

<style scoped>

</style>
